#define _CRT_SECURE_NO_WARNINGS 1


#include<vector>
#include<iostream>

using namespace std;

void BackTrack(vector<int>& nums, int n, int start, vector<int>& v)
{
    if (start == n)
    {
        int sum = 0;
        for (auto& e : nums)
        {
            sum = sum * 10 + e;
        }

        v.push_back(sum);
        return;
    }

    for (int i = start; i < n; i++)
    {
        swap(nums[i], nums[start]);
        BackTrack(nums, n, start + 1, v);
        swap(nums[i], nums[start]);
    }
}

int main()
{
    int q = 0;
    cin >> q;

    while (q--)
    {
        int n = 0;
        cin >> n;

        if (n % 2 == 0)
        {
            cout << n << endl;
        }
        else
        {
            vector<int> v;
            while (n)
            {
                v.push_back(n % 10);
                n /= 10;
            }

            vector<int> ret;
            BackTrack(v, v.size(), 0, ret);

            for (auto& e : ret)
            {
                if (e % 2 == 0)
                {
                    cout << e << endl;
                    goto end;
                }
            }

            cout << -1 << endl;
        }
    end:;
    }

    return 0;
}